#!/usr/bin/env python3

import numpy as np
from scipy import interpolate
import matplotlib.pyplot as plt

# 生成数据
x = np.array([0, 1, 2, 3, 0.5])
y = np.array([0, 1, 1.5, 3.5, 3])

# 定义B样条插值的阶数
k = 3

# 进行B样条插值
tck, u = interpolate.splprep([x, y], k=k)

# 生成插值后的数据
unew = np.linspace(0, 1, 1000)
out = interpolate.splev(unew, tck)

# 绘制结果
plt.plot(x, y, 'ro', out[0], out[1], 'b')
plt.show()
